package com.wc.AlgoOJ_homework.AlgoOJ_HomeWork2.N_子串分值和;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/6 9:01
 * @description http://43.138.190.70:8888/p/169?tid=65e6b15c27489dab814f8d41
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static char[] s;
    static int n;
    // 这个是可以优化的
    static char[] lastIdx = new char[128];

    // 考虑贡献值
    public static void main(String[] args) {
        s = sc.next().toCharArray();
        n = s.length;
        long res = 0;
        for (int i = 0; i < n; i++) {
            int l = i - 1;
            // 找左边第一次出现的的s[i]因为只有他能让当前的s[i]没有贡献，后面的没他出现的早就说明他是第一个出现的
            while (l >= 0 && s[l] != s[i]) {
                l--;
            }
            res += (long) (i - l) * (n - i);
        }

        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}